package chat.web.filter;

import java.io.IOException;
import javax.servlet.*; 
import javax.servlet.annotation.*;
import javax.servlet.http.HttpServletRequest;

import org.apache.logging.log4j.*; 
/**
 * Servlet Filter implementation class JspFilter
 */
@WebFilter(dispatcherTypes = {DispatcherType.REQUEST } , urlPatterns = { "/*" })
public class JspFilter implements Filter {
	
	/**
	 * Log4j logger
	 */
	static final Logger logger = LogManager.getLogger(JspFilter.class);

    /**
     * Default constructor. 
     */
    public JspFilter() { 
    }

	/**
	 * @see Filter#destroy()
	 */
	public void destroy() { 
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		
		// place your code here
		
		String reqUrl = request.getServletContext().getContextPath() ;
		if( request instanceof HttpServletRequest ) { 
			HttpServletRequest hRequest = (HttpServletRequest) request ;
			reqUrl += "/" + hRequest.getRequestURL();
		}
		
		request.setCharacterEncoding("UTF-8"); 
		
		logger.trace( "Request URL: " + reqUrl ); 

		// end of placing your code here

		// pass the request along the filter chain
		chain.doFilter(request, response);
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {  
		
	}

}
